/*
 * ContribuyentesImpuestosVerFrame.java
 *
 * Created on 24 de abril de 2008, 06:49 PM
 */
package org.vehiculos.generales;

import org.vehiculos.generales.VehiculosImpuestosInscripcionAgregarFrame;
import org.mybeans.Sesion;



import org.mybeans.RegimenVehiculosBeans;
import org.mybeans.VehiculosBeans;
import org.vehiculos.busquedas.VehiculosBusquedaConPlacaFrame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.menu.MenuVehiculos;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author  avbravo
 */
public class VehiculosImpuestosRegistrosFrame extends javax.swing.JFrame {

    boolean focoVehiculo = false;
    boolean focoImpuestos = false;
   
    Sesion sesion;
    VehiculosBeans vehiculosBeans;
    RegimenVehiculosBeans regimenVehiculosBeans;
    int fila = -1;
    int Anio;
    int NumeroMes;
    DefaultTableModel modelo;
    String Placa;
    int IdVehiculo;

    /** Creates new form ContribuyentesImpuestosVerFrame */
    public VehiculosImpuestosRegistrosFrame() {
        initComponents();
        sesion = new Sesion();


        /*
         * Fondo
         */

         
         
         

        jPanel3.setOpaque(false);
        setContentPane(jPanel3);

        /*
         * fin del fondo
         */
        vehiculosBeans = new VehiculosBeans();
        regimenVehiculosBeans = new RegimenVehiculosBeans();

        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
        this.Anio = ca.get(java.util.Calendar.YEAR);
        NumeroMes = ca.get(java.util.Calendar.MONTH);

        sesion.setAnio(this.Anio);

        modelo = (DefaultTableModel) jXTable1.getModel();


        TableColumn columnId = jXTable1.getColumnModel().getColumn(0);
        columnId.setPreferredWidth(130);

        TableColumn columnRegimen = jXTable1.getColumnModel().getColumn(1);
        columnRegimen.setPreferredWidth(130);



        Limpiar();
        MenuVehiculos menuVehiculos = new MenuVehiculos();
        menuVehiculos.VerificarPrivilegios();

     
        if (menuVehiculos.isBjMenuItemVehiculosImpuestosAgregar()) {
            jButtonAgregar.setVisible(true);
        } else {
            jButtonAgregar.setVisible(false);
        }


        if (menuVehiculos.isBjMenuItemVehiculosImpuestosEliminar()) {
            jButtonEliminar.setVisible(true);

        } else {
            jButtonEliminar.setVisible(false);
        }


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldPlaca = new javax.swing.JTextField();
        jTextFieldVehiculo = new javax.swing.JTextField();
        jButtonBuscarContribuyentes = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTable1 = new org.jdesktop.swingx.JXTable();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldIdRegimen = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldRegimen = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldValor = new javax.swing.JTextField();
        jButtonAgregar = new javax.swing.JButton();
        jButtonVistaPrevia = new javax.swing.JButton();
        jButtonImprimir = new javax.swing.JButton();
        jButtonEliminar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Registros Impuestos Vehiculos");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Placa");

        jLabel2.setText("Vehiculo");

        jTextFieldPlaca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldPlacaActionPerformed(evt);
            }
        });

        jTextFieldVehiculo.setEditable(false);

        jButtonBuscarContribuyentes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/search.png"))); // NOI18N
        jButtonBuscarContribuyentes.setMnemonic('b');
        jButtonBuscarContribuyentes.setToolTipText("Buscar");
        jButtonBuscarContribuyentes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarContribuyentesActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setMnemonic('r');
        jButtonRegresar.setToolTipText("Cerrar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jXTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Regimen", "Valor", "Periodo", "Mes", "Inscripcion"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, true, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jXTable1.setOpaque(false);
        jScrollPane1.setViewportView(jXTable1);

        jLabel5.setText("Codigo");

        jTextFieldIdRegimen.setEditable(false);

        jLabel6.setText("Regimen");

        jTextFieldRegimen.setEditable(false);

        jLabel7.setText("Valor");

        jTextFieldValor.setEditable(false);
        jTextFieldValor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldValorActionPerformed(evt);
            }
        });

        jButtonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/impuestos.png"))); // NOI18N
        jButtonAgregar.setToolTipText("Agregar impuestos");
        jButtonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAgregarActionPerformed(evt);
            }
        });

        jButtonVistaPrevia.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/preview.png"))); // NOI18N
        jButtonVistaPrevia.setToolTipText("Vista Previa");
        jButtonVistaPrevia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVistaPreviaActionPerformed(evt);
            }
        });

        jButtonImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/print.jpeg"))); // NOI18N
        jButtonImprimir.setToolTipText("Imprimir");
        jButtonImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonImprimirActionPerformed(evt);
            }
        });

        jButtonEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/delete.png"))); // NOI18N
        jButtonEliminar.setToolTipText("Eliminar");
        jButtonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEliminarActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButton1.setToolTipText("Regresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 884, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jTextFieldPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonBuscarContribuyentes, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())
                            .addComponent(jTextFieldVehiculo, javax.swing.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(47, 47, 47)
                        .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(716, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(24, 24, 24)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 393, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldIdRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jButtonVistaPrevia, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(399, Short.MAX_VALUE))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextFieldPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonBuscarContribuyentes, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                            .addComponent(jButtonRegresar))
                        .addGap(6, 6, 6))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButtonAgregar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldVehiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jButtonEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonImprimir, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE))
                    .addComponent(jButtonVistaPrevia, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldIdRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldRegimen, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonBuscarContribuyentesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarContribuyentesActionPerformed

    VehiculosBusquedaConPlacaFrame vehiculosBusquedaConPlacaFrame = new VehiculosBusquedaConPlacaFrame();
    vehiculosBusquedaConPlacaFrame.setLocationRelativeTo(null);
    vehiculosBusquedaConPlacaFrame.setVisible(true);
    focoVehiculo = true;
    focoImpuestos = false;
}//GEN-LAST:event_jButtonBuscarContribuyentesActionPerformed

private void jTextFieldValorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldValorActionPerformed
}//GEN-LAST:event_jTextFieldValorActionPerformed

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jTextFieldPlacaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldPlacaActionPerformed
    CargarVehiculos();


}//GEN-LAST:event_jTextFieldPlacaActionPerformed

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    // TODO add your handling code here:
    try {

        if (focoVehiculo) {

            Actualizar();
        } else {
            if (focoImpuestos) {
                CargarImpuestos();
            }
        }
        focoImpuestos = false;
        focoVehiculo = false;
    } catch (Exception ex) {
        sesion.MostrarMensajeError("Error ", "Boton Actualizar Impuestos()\n " + ex.getMessage().toString());
    }
}//GEN-LAST:event_formWindowGainedFocus

private void jButtonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAgregarActionPerformed
    // TODO add your handling code here:
    if (this.IdVehiculo == 0) {
        JOptionPane.showMessageDialog(this, "Ingrese la placa del vehiculo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    sesion.setIdVehiculo(String.valueOf(this.IdVehiculo));
    VehiculosImpuestosInscripcionAgregarFrame impuestosInscripcionAgregarFrame = new VehiculosImpuestosInscripcionAgregarFrame();
    impuestosInscripcionAgregarFrame.setLocationRelativeTo(null);
    impuestosInscripcionAgregarFrame.setVisible(true);
    focoVehiculo = false;
    focoImpuestos = true;
}//GEN-LAST:event_jButtonAgregarActionPerformed

private void jButtonVistaPreviaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVistaPreviaActionPerformed
    // TODO add your handling code here:
    String Placa = this.jTextFieldPlaca.getText();
    if (Placa == null || Placa.equals("")) {
        JOptionPane.showMessageDialog(this, "Ingrese la placa ", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
        jTextFieldPlaca.requestFocus();
        return;
    }

    String vehiculo = this.jTextFieldVehiculo.getText();
    if (vehiculo == null || vehiculo.equals("")) {
        JOptionPane.showMessageDialog(this, "Ingrese la placa", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
        jTextFieldVehiculo.requestFocus();
        return;
    }

    String reportSource;
    reportSource = sesion.getRutaReportes() + "VehiculosImpuestos.jrxml";
    String reportDest;
    reportDest = sesion.getRutaDestino() + "VehiculosImpuestos.html";

    Map<String, Object> params = new HashMap<String, Object>();

    try {
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_PLACA", Placa);
        params.put("P_IDVEHICULO", this.IdVehiculo);
        params.put("P_VEHICULO", vehiculo);
        params.put("P_MUNICIPIO", sesion.getMunicipio());

        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);

        JasperViewer.viewReport(jasperPrint, false);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonVistaPreviaActionPerformed

private void jButtonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImprimirActionPerformed
    // TODO add your handling code here:
    String Placa = this.jTextFieldPlaca.getText();
    if (Placa == null || Placa.equals("")) {
        JOptionPane.showMessageDialog(this, "Ingrese la placa ", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
        jTextFieldPlaca.requestFocus();
        return;
    }

    String vehiculo = this.jTextFieldVehiculo.getText();
    if (vehiculo == null || vehiculo.equals("")) {
        JOptionPane.showMessageDialog(this, "Ingrese la placa", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
        jTextFieldVehiculo.requestFocus();
        return;
    }
    String reportSource;
    reportSource = sesion.getRutaReportes() + "VehiculosImpuestos.jrxml";
    String reportDest;
    reportDest = sesion.getRutaDestino() + "VehiculosImpuestos.html";

    Map<String, Object> params = new HashMap<String, Object>();

    try {
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_PLACA", Placa);
        params.put("P_IDVEHICULO", this.IdVehiculo);
        params.put("P_VEHICULO", vehiculo);
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);

        JasperPrintManager.printReport(jasperPrint, true);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonImprimirActionPerformed

private void jButtonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEliminarActionPerformed
    // TODO add your handling code here:
      try {

         
            String IdRegimen = jTextFieldIdRegimen.getText();

            if (IdRegimen == null || IdRegimen.equals("")) {
                sesion.MostrarMensajeAdvertencia("Mensaje", "Seleccione un regimen");
                return;
            }
            String Regimen = jTextFieldRegimen.getText();
            if (Regimen == null || Regimen.equals("")) {
                sesion.MostrarMensajeAdvertencia("Mensaje", "Seleccione un regimen");
                return;
            }
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            //poner el estatus a inactivo
            int res = JOptionPane.showConfirmDialog(this, "Desea eliminar este regimen " + IdRegimen + "\n Regimen: " + Regimen,
                    "Eliminar Regimen ", JOptionPane.YES_NO_OPTION);
            if (res == JOptionPane.YES_OPTION) {

                String sql = " delete  from regimenvehicles  where idmunicipio=? and idvehiculo= ? and idregimen=? and activo='si' ";
                PreparedStatement prest = sesion.con.prepareStatement(sql);
                prest.setString(1, sesion.getIdmunicipio());
                prest.setInt(2, this.IdVehiculo);
                prest.setString(3, IdRegimen);
                prest.executeUpdate();

                //-------------------------------------*
               
            java.util.Calendar ca = java.util.Calendar.getInstance();
            java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());

            int Anio = ca.get(java.util.Calendar.YEAR);

            //pagosmensuales
            sql = " delete from  pagosmensuales "
                    + " where idmunicipio=? and id= ? and tipoid=? "
                    + " and anio= ? and idregimen=? and activo='si' ";
            prest = sesion.con.prepareStatement(sql);
            prest.setString(1, sesion.getIdmunicipio());
            prest.setString(2, String.valueOf(this.IdVehiculo));
            prest.setString(3, "vehiculos");
            prest.setInt(4, Anio);
            prest.setString(5, IdRegimen);
            prest.executeUpdate();


            //pagosanuales
            sql = " delete from  pagosanuales "
                    + " where idmunicipio=? and id= ? and tipoid=? "
                    + " and anio= ? and idregimen=? and activo='si' ";
            prest = sesion.con.prepareStatement(sql);
            prest.setString(1, sesion.getIdmunicipio());
            prest.setString(2, String.valueOf(this.IdVehiculo));
            prest.setString(3, "vehiculos");
            prest.setInt(4, Anio);
            prest.setString(5, IdRegimen);
            prest.executeUpdate();


             //morosidadmensual
            sql = " delete from  morosidadmensual "
                    + " where idmunicipio=? and id= ? and tipoid=? "
                    + " and anio= ? and idregimen=?  ";
            prest = sesion.con.prepareStatement(sql);
            prest.setString(1, sesion.getIdmunicipio());
            prest.setString(2, String.valueOf(this.IdVehiculo));
            prest.setString(3, "vehiculos");
            prest.setInt(4, Anio);
            prest.setString(5, IdRegimen);
            prest.executeUpdate();

              //recargomensual
            sql = " delete from  recargomensual "
                    + " where idmunicipio=? and id= ? and tipoid=? "
                    + " and anio= ? and idregimen=?  ";
            prest = sesion.con.prepareStatement(sql);
            prest.setString(1, sesion.getIdmunicipio());
            prest.setString(2, String.valueOf(this.IdVehiculo));
            prest.setString(3, "vehiculos");
            prest.setInt(4, Anio);
            prest.setString(5, IdRegimen);
            prest.executeUpdate();


             //cierremorosidadmensual
            sql = " delete from  cierremorosidadmensual "
                    + " where idmunicipio=? and id= ? and tipoid=? "
                    + " and anio= ? and idregimen=?  ";
            prest = sesion.con.prepareStatement(sql);
            prest.setString(1, sesion.getIdmunicipio());
            prest.setString(2, String.valueOf(this.IdVehiculo));
            prest.setString(3, "vehiculos");
            prest.setInt(4, Anio);
            prest.setString(5, IdRegimen);
            prest.executeUpdate();

//cierremorosidadmensualanual
            sql = " delete from  cierremorosidadmensualanual "
                    + " where idmunicipio=? and id= ? and tipoid=? "
                    + " and anio= ? and idregimen=?  ";
            prest = sesion.con.prepareStatement(sql);
            prest.setString(1, sesion.getIdmunicipio());
            prest.setString(2, String.valueOf(this.IdVehiculo));
            prest.setString(3, "vehiculos");
            prest.setInt(4, Anio);
            prest.setString(5, IdRegimen);
            prest.executeUpdate();

             //cierrerecargomensual
            sql = " delete from  cierrerecargomensual "
                    + " where idmunicipio=? and id= ? and tipoid=? "
                    + " and anio= ? and idregimen=?  ";
            prest = sesion.con.prepareStatement(sql);
            prest.setString(1, sesion.getIdmunicipio());
            prest.setString(2, String.valueOf(this.IdVehiculo));
            prest.setString(3, "vehiculos");
            prest.setInt(4, Anio);
            prest.setString(5, IdRegimen);
            prest.executeUpdate();
                sesion.con.close();
                JOptionPane.showMessageDialog(this, "Regimen eliminando exitosamente", "Eliminado", JOptionPane.INFORMATION_MESSAGE);
                CargarImpuestos();
            } else {
                JOptionPane.showMessageDialog(this, "No se elimino el regimen.", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "jMenuItemPagarActionPerformed()\n " + ex.getMessage().toString());
        }
}//GEN-LAST:event_jButtonEliminarActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    dispose();
}//GEN-LAST:event_jButton1ActionPerformed

    private void CargarVehiculos() {

        try {
            Limpiar();
            String Placa = this.jTextFieldPlaca.getText();
            if (Placa == null || Placa.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese la placa del vehiculo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            vehiculosBeans.setPlaca(Placa);

            if (vehiculosBeans.ConsultarPorPlaca() == true) {

                if (vehiculosBeans.getPlaca() == null || vehiculosBeans.getPlaca().equals("")) {
                    JOptionPane.showMessageDialog(this, "Este vehiculo no tiene asiganda una placa...", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }


                vehiculosBeans.setTipoId(vehiculosBeans.getTipoId().toLowerCase());

                Actualizar();

            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }


    }

    private void Actualizar() {
        try {

            jTextFieldPlaca.setText(vehiculosBeans.getPlaca());
            this.Placa = vehiculosBeans.getPlaca();
            if (vehiculosBeans.getIdVehiculo() == null || vehiculosBeans.getIdVehiculo().equals("")) {
                this.IdVehiculo = 0;
                JOptionPane.showMessageDialog(this, "Este vehiculo no tiene un codigo asignado", "Advertencia", JOptionPane.WARNING_MESSAGE);
            } else {
                this.IdVehiculo = Integer.parseInt(vehiculosBeans.getIdVehiculo());
            }

            String dueno = "";
            if (vehiculosBeans.getDueno() == null) {
                dueno = "";
            } else {
                dueno = " Dueño " + vehiculosBeans.getDueno();
            }
            jTextFieldVehiculo.setText(vehiculosBeans.getMarca() + " Modelo: " + vehiculosBeans.getModelo() + dueno);

            String TipoId = vehiculosBeans.getTipoId();
            String idOld = vehiculosBeans.getId();
            TipoId = TipoId.toLowerCase();
            if (TipoId.equals("contribuyentes")) {
            } else {
                if (TipoId.equals("comercios")) {
                }
            }



            CargarImpuestos();
            repaint();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VehiculosImpuestosRegistrosFrame().setVisible(true);
            }
        });
    }

    public void CargarImpuestos() {
        try {
            Limpiar();
            // String cedula = jTextFieldPlaca.getText();
            String sql = "select regimenvehicles.*, regimen.regimen from  regimenvehicles, regimen where regimenvehicles.idmunicipio=? and regimenvehicles.idvehiculo =? and regimenvehicles.activo='si' and regimenvehicles.idregimen = regimen.idregimen and regimen.idmunicipio=?";
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            PreparedStatement psquery = sesion.con.prepareStatement(sql);
            psquery.setObject(1, sesion.getIdmunicipio());
            psquery.setObject(2, this.IdVehiculo);
            psquery.setObject(3, sesion.getIdmunicipio());
            ResultSet rs = psquery.executeQuery();

            // modelo = new DefaultTableModel();
            // Creamos las columnas.
            // modelo.addColumn("codigo");
            // modelo.addColumn("regimen");
            // modelo.addColumn("valor");
            // modelo.addColumn("periodo");
            //modelo.addColumn("mes");
            //modelo.addColumn("Inscripcion");

// Bucle para cada resultado en la consulta
            while (rs.next()) {
                // Se crea un array que será una de las filas de la tabla.
                Object[] fila = new Object[6]; // Hay tres columnas en la tabla

                fila[0] = rs.getString("idregimen");
                fila[1] = rs.getString("regimen");
                fila[2] = rs.getString("valor");
                fila[3] = rs.getString("periodopago");
                fila[4] = rs.getString("mespago");
                java.util.Calendar ca = java.util.Calendar.getInstance();
                java.sql.Date mydate = rs.getDate("fechainscripcion");
                //fila[5] = rs.getDate("fechainscripcion");
                Format formatter;
                formatter = new SimpleDateFormat("dd/MM/yyyy");
                String s = formatter.format(mydate);
                fila[5] = s;
                modelo.addRow(fila);

            }
            this.jXTable1.setModel(modelo);
            jXTable1.setVisible(true);

            this.jXTable1.addMouseListener(new MouseAdapter() {

                public void mouseClicked(MouseEvent e) {
                    if (SwingUtilities.isRightMouseButton(e)) {

                    }
                    fila = jXTable1.rowAtPoint(e.getPoint());
                    int columna = jXTable1.columnAtPoint(e.getPoint());
                    if ((fila > -1) && (columna > -1)) {
                        String idRegimen = String.valueOf(jXTable1.getValueAt(fila, 0));
                        String regimen = String.valueOf(jXTable1.getValueAt(fila, 1));
                        String Svalor = String.valueOf(jXTable1.getValueAt(fila, 2));
                        Double valor = Double.parseDouble(Svalor);
                        String periodoPago = String.valueOf(jXTable1.getValueAt(fila, 3));
                        String mesPago = String.valueOf(jXTable1.getValueAt(fila, 4));
                        regimenVehiculosBeans.setIdRegimen(idRegimen);
                        regimenVehiculosBeans.setRegimen(regimen);
                        regimenVehiculosBeans.setValor(valor);
                        regimenVehiculosBeans.setPeriodoPago(periodoPago);
                        regimenVehiculosBeans.setMesPago(mesPago);
                        jTextFieldIdRegimen.setText(idRegimen);
                        jTextFieldRegimen.setText(regimen);
                        jTextFieldValor.setText(String.valueOf(valor));

                    }
                }
            });
            TableColumn column = jXTable1.getColumnModel().getColumn(1);
            column.setPreferredWidth(250);
            sesion.con.close();
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error", "CargarImpuestos()" + ex.getMessage().toString());
        }

    }

    private void Limpiar() {
        jTextFieldIdRegimen.setText("");
        jTextFieldRegimen.setText("");
        jTextFieldValor.setText("");
        LimpiarTable();
    }

    private void LimpiarTable() {
        try {
            //limpiar  el jXTable

            boolean control = false;
            while (control == false) {
                int n = jXTable1.getRowCount();
                //System.out.println("n" + n);
                if (n <= 0) {
                    control = true;
                } else {
                    modelo.removeRow(0);
                }

            }//while
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error", "LimpiarTable()" + ex.getMessage().toString());
        }
    }

 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonAgregar;
    private javax.swing.JButton jButtonBuscarContribuyentes;
    private javax.swing.JButton jButtonEliminar;
    private javax.swing.JButton jButtonImprimir;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JButton jButtonVistaPrevia;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextFieldIdRegimen;
    private javax.swing.JTextField jTextFieldPlaca;
    private javax.swing.JTextField jTextFieldRegimen;
    private javax.swing.JTextField jTextFieldValor;
    private javax.swing.JTextField jTextFieldVehiculo;
    private org.jdesktop.swingx.JXTable jXTable1;
    // End of variables declaration//GEN-END:variables
}
